package com.kingint.web.portal.serve.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.kingint.common.unitedresult.K;
import com.kingint.mbg.group.Insert;
import com.kingint.mbg.ser.entity.SerSendMessage;
import com.kingint.web.portal.serve.service.SendMessageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/sendMessage")
@Api(value = "SendMessageController", description = "前端群发通知表")
@CrossOrigin
public class SendMessageController {

    @Resource
    private SendMessageService sendMessageService;

    @ApiOperation(value = "添加群发通知表")
    @PostMapping("/create")
    public Object create(@Validated(Insert.class) @RequestBody SerSendMessage serSendMessage) {
        int i = sendMessageService.insertSendMessageInfo(serSendMessage);
        if(i>0){
            return K.ok().data(i);
        }
        return K.error();
    }

    @ApiOperation(value = "查询群发通知未确认的")
    @GetMapping("/unConfirmMessage")
    public Object unConfirmMessage() {
        List<SerSendMessage> list = sendMessageService.unConfirmMessage();
        return K.ok().data(list);
    }

    //查询已回复的群发通知
    @ApiOperation(value = "查询群发通知已确认的")
    @GetMapping("/confirmMessage")
    public Object confirmMessage() {
        List<SerSendMessage> list = sendMessageService.confirmMessage();
        return K.ok().data(list);
    }

    @ApiOperation(value = "查询群发通列表信息（用户所有的群发通知）")
    @GetMapping("/getSendMessageList")
    public Object getSendMessageList(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                     @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
        IPage<SerSendMessage> list = sendMessageService.getSendMessageList(pageNum,pageSize);
        return K.ok().data(list);
    }


    //查询对应的群发通知详情
    @ApiOperation(value = "查询对应的群发通知详情")
    @GetMapping("/queryDetails")
    public Object queryDetails(@RequestParam(value = "id") Integer id) {
        SerSendMessage info = sendMessageService.queryDetails(id);
        return K.ok().data(info);
    }
    //对应群发通知确认回复
    @ApiOperation(value = "对应群发通知确认回复")
    @GetMapping("/confirmReply")
    public Object confirmReply(@RequestParam(value = "id") Integer id) {
        Integer i = sendMessageService.confirmReply(id);
        if(i>0){
            return K.ok().data(i);
        }
        return K.error();
    }
}
